package com.lut.reservation.controller;

import com.lut.reservation.bean.Result;
import com.lut.reservation.bean.User;
import com.lut.reservation.service.UserService;
import com.lut.reservation.util.ResultUtil;
import org.springframework.web.bind.annotation.*;

/**
 * @author zyt
 */
@RestController
@RequestMapping("/api/user")
public class UserController extends BaseController<UserService, User> {

  @GetMapping("/info")
  public Result<User> getUserInfo(@SessionAttribute(value = "userId", required = false) Integer userId) {
    //从数据库查询该用户
    User user = service.getById(userId);
    return ResultUtil.success(user);
  }

  @PostMapping("{id}/info")
  public Result<User> updateInfo(@RequestBody User user) {
    service.updateById(user);
    return ResultUtil.success(user);
  }
}
